<!--
 * @description  : 岗员协同文书发起
 * @descriptionDetail: 岗员协同文书发起
 * @copyright    : 浙江烟草
 * @author       : mwq
 * @create       : 2022-09-29 11:25:58
-->

<template>
  <view>
    <!-- #ifdef H5-ONLY -->
    <theme-navbar
      :is-white="false"
      title="岗员协同"
      :custom-back="goBack"
      style="z-index: 99999"
    >
    </theme-navbar>
    <!-- #endif -->
    <view>
      <u-row>
        <u-col span="12">
          <view class="news-title" style="margin:3%;font-size:14px;text-align:center">
            提交后自动生成文书编号
          </view>
        </u-col>
      </u-row>
      <u-form ref="uForm" v-model="docFrom" :rules="rules" style="margin:3%">
        <u-form-item label="协同主题" :label-width="labelWidth" :required="true">
          <u-input :disabled="true" :custom-style="pointerStyle" :border="border" type="textarea" :select-open="dictShow" placeholder="请选择" v-model="showData.dataName" @click="showTeam"></u-input>
        </u-form-item>
        <u-form-item label="登记日期" :label-width="labelWidth" :required="true">
          <u-input :disabled="true"  v-model="docFrom.teamworkDate"></u-input>
        </u-form-item>
        <u-form-item label="发起部门" :label-width="labelWidth" prop="inputrDeptName" :required="true">
          <u-input :disabled="true"  v-model="docFrom.inputrDeptName"></u-input>
        </u-form-item>
        <u-form-item label="发起人员" :label-width="labelWidth" prop="inputrName" :required="true">
          <u-input :disabled="true"  v-model="docFrom.inputrName"></u-input>
        </u-form-item>
        <u-form-item label="接收人员" :label-width="labelWidth" prop="inquirePersonNames" :required="true">
          <u-input :disabled="true" :custom-style="pointerStyle" placeholder="请选择" v-model="docFrom.inquirePersonNames" @click="handelPerson"></u-input>
        </u-form-item>
        <u-form-item label="来源" :label-width="labelWidth" :required="true">
          <z-dict-radio dictType="I_COLLABORATION_SOURCE" v-model="docFrom.teamworkOrigin" @confirm="handleDicly"></z-dict-radio>
        </u-form-item>
        <u-form-item label="协同事项描述" :label-width="labelWidth" :required="true">
          <u-input type="textarea" placeholder="请输入" :maxlength="maxLength" v-model="docFrom.abnormalSituation"></u-input>
        </u-form-item>
        <u-form-item :label-width="labelWidth" label="附件上传">
          <upload-images
            :url="uploadFile"
            :length="10"
            :extForm="{fiGroupCode: $FILE_GROUP_TYPE.s_doc_word_instance, bizId: mainInfo.bizUuid}"
            :bizId="mainInfo.bizUuid"
            :del-url="delUrl"
            :can-add="true"
            :can-del="true"
            :renderImages="renderImages"
            ref="saveModel3"
          >
          </upload-images>
        </u-form-item>
      </u-form>
      <view class="space-content"></view>
      <view class="submit-btns btn-other-cls">
        <u-button class="u-btn" type="primary" @click="handleEnd">
          提交
        </u-button>
      </view>
    </view>
    <u-popup mode="bottom" height="80%" v-model="orgPersonSelectShow">
      <org-person-select treeType="ng-dept" @choose="handlerChoosePerson"></org-person-select>
    </u-popup>
    <u-popup mode="bottom" height="80%" border-radius="14" v-model="dictShow">
      <single-select :extHide="true" :isWrap="true" :mDatas="dictList" @m-select="handleDictConfirm"></single-select>
    </u-popup>
  </view>
</template>

<script>
import store from '@/store';
import internalService from '@/service/internal/internal.service';
import commonService from "@/service/common/common.service.js";
import {uuid,} from "@/common/util.js";
import {ZDictRadio,} from '@/components'
import {dateUtils,} from "@/common/util.js";
import {UploadImages, } from "@/components";
import OrgPersonSelect from "@/components/org-person-select.vue";
import SingleSelect from "@/components/single-select.vue";
let date = new Date();
export default {
  components:{UploadImages,OrgPersonSelect,ZDictRadio,SingleSelect,},
  data(){
    return{
      docInsUuid:'',
      docUuid: '',
      border: false,
      mainInfo: {
        typeCode: 'INTERNAL_APPROVE',
        itemCode: 'YW_TEAMWORK',
        docCode: 'teamwork',
        bizUuid: '',
      },
      docConfig:{},
      docFrom:{
        teamworkTheme:'',
        teamworkOrigin:'',
        teamworkDate:dateUtils.dateFormat('yyyy-MM-dd',new Date()),
        inputrDeptName:'',  // 发起部门
        sendCompUuid:'', // 发起部门id
        inputrName:'',  // 发起人员
        inputrPersonUuid:'', // 发起人员uuid
        inquirePersonNames:'', // 接收人员
        inquirePersonUuids:'',// 接收人员uuid
        receiveCompUuid:'', // 接受部门uuid
        abnormalSituation:'', // 协同描述
        listId:'',
      },
      labelWidth: '200',
      maxLength:330,
      uploadFile: commonService.uploadFile,
      delUrl: commonService.deleteFile,
      orgPersonSelectShow:false,
      titemUuid:'',
      errorType: ["message",],
      rules: {
        teamworkTheme: [{
          required: true,
          message: '请选择',
          trigger:'change',
        },],
        teamworkOrigin: [{
          required: true,
          message: '请选择',
          trigger:'change',
        },],
        inquirePersonNames: [{
          required: true,
          message: '请选择',
          trigger:'change',
        },],
        abnormalSituation: [{
          required: true,
          message: '请输入',
          trigger:'change',
        },],
      },
      dictList:[],
      dictShow:false,
      showData:{},
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx start
			pointerStyle: {
			  marginRight: "5px",
				pointerEvents: "none !important"
			},
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx end
    }
  },
  created(){
    let dictDatas = store.state.dicts['I_TEAMWORK_THEME'];
    dictDatas.forEach((d) => {
      this.dictList.push({uid:d.bcbCode,name:d.bcbName,});
    })
    console.log('dictList',this.dictList);
    internalService.getInternalDocConfig('coordination').then((res) => {
      const docData = res.data[0];
      if (res.success) {
        this.docUuid = docData.docUuid;
        this.mainInfo.itemCode = docData.itemCode;
        this.docConfig = docData;
        this.showDialog = true;
      }
      commonService.getById( this.docUuid);// 获取文书初始化信息
      commonService.getDoc({id: this.docInsUuid,docUuid: this.docUuid,bizUuid: this.mainInfo.bizUuid,},this.docConfig.controllerPath,this.docConfig.docType).then((res) => {
        this.docFrom.inputrDeptName = res.data[0].inputrDeptName;
        this.docFrom.inputrPersonUuid = res.data[0].inputrPersonUuid;
        this.docFrom.inputrName = res.data[0].inputrName;

      });

    });
    this.mainInfo.bizUuid = uuid();
    commonService.initOtherMain(this.mainInfo).then((res) => {
      this.titemUuid = res.bean.titemUuid;
    });

  },
  methods:{
    renderImages(){
			// UploadImages组件renderImages方法必须返回 Promise对象 2023-10-27 fsx start
			return new Promise((res, rej) => {
				commonService.findFileByFileId(this.mainInfo.bizUuid).then(r => {
					if(r.code == 200 && r.success && Array.isArray(r.data)) {
						r.data.forEach(i => {
							i.src = `${commonService.downloadFile}?fileId=${i.gfiId}&tk=${uni.getStorageSync("tk")}`;
							i.filePath = i.src;
						});
						res(r.data);
					} else {
					 res([]);
					}
				});
			})
			// UploadImages组件renderImages方法必须返回 Promise对象 2023-10-27 fsx end
    },
    handleDictConfirm(v){
      console.log(v);
      this.showData.dataName = v.name;
      this.showData.dataValue = v.uid;
      this.dictShow = false;
    },
    handleDicly(){
    },
    handleEnd(){
      this.saveDoc();
    },
    saveDoc(){
      this.docFrom.teamworkTheme =  this.showData.dataName;
      if(!this.docFrom.teamworkTheme || !this.docFrom.teamworkDate || !this.docFrom.inputrDeptName || !this.docFrom.inputrName || !this.docFrom.inquirePersonNames || !this.docFrom.teamworkOrigin || !this.docFrom.abnormalSituation){
        this.$u.toast('请检查是否有未填项目!')
        return false
      }
      this.docFrom.listId = this.mainInfo.bizUuid;
      commonService.saveDoc(this.docFrom,this.docConfig.controllerPath,{titemUuid: this.titemUuid,docUuid: this.docUuid, },this.docConfig.docType).then((res) => {
        if(res.success){
          this.submitDoc();
        }else{
          this.$u.toast(res.msg)
        }
      })
    },
    submitDoc(){
      this.docFrom.listId = this.mainInfo.bizUuid
      this.$modal.showLoading("加载中...");
      commonService.submit(this.docFrom,this.docConfig.controllerPath,{titemUuid: this.titemUuid,docUuid: this.docUuid,nextPersons:this.docFrom.inquirePersonUuids,belong:'internal', },this.docConfig.docType).then((res) => {
        if(res.success){
          this.$modal.hideLoading();
          this.$u.toast('文书提交成功')
          this.backPrev();
        }else{
          this.$u.toast(res.msg)
        }
      })
    },
    handlerChoosePerson(psrList) {
      console.log(psrList);
      let names = [];
      let ids = [];
      let pid = [];
      psrList.forEach(p => {
        names.push(p.name);
        ids.push(p.id);
        pid.push(p.pId);
      });
      this.docFrom.receiveCompUuid = pid.join(",");
      this.docFrom.inquirePersonNames = names.join(",");
      this.docFrom.inquirePersonUuids = ids.join(",")
      this.orgPersonSelectShow = false;
    },
    handelPerson(){
      this.orgPersonSelectShow = true;
    },
    showTeam(){
      this.dictShow = true;
    },
  },
}
</script>

<style lang="scss" scope>
/*展示上拉加载的数据列表*/
.news-li {
  font-size: 32rpx;
  padding: 32rpx;
  border-bottom: 1rpx solid #eee;
}
.news-row {
  width: 100%;
}
.news-logo {
  width: 80rpx;
  height: 80rpx;
  text-align: center;
  // line-height: 80px;
  font-size: 28rpx;
  color: #eee;
  border-radius: 30rpx;
  background: #027aff;
}
.news-title {
  font-size: 24rpx;
  font-weight: 600;
  color: #333333;
}
.news-content-box{

}
.news-card{
  display: inline-block;
  padding: 8rpx;
  color: #666680;
  font-size: 24rpx;
  background: #EFF3F9;
  margin-right: 16rpx;
}

::v-deep .u-drawer .u-drawer-content .u-drawer__scroll-view .uni-scroll-view .uni-scroll-view .uni-scroll-view-content .u-action-sheet-item{
    word-break:normal;
    width:auto;
    display:block;
    white-space:pre-wrap;
    word-wrap : break-word ;
    overflow: hidden ;
    line-height: 1.2;
}
</style>
